package com.lzy.cloud.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.base.dto.BaseLicenceDto;
import com.lzy.cloud.base.entity.BaseLicence;
import com.lzy.cloud.base.mapper.BaseLicenceMapperExt;
import com.lzy.cloud.base.service.LicenceService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LicenceServiceImpl implements LicenceService {

    @Autowired
    private BaseLicenceMapperExt baseLicenceMapperExt;

    @Override
    public Long insert(BaseLicenceDto baseLicenceDto) {
        BaseLicence baseLicence = DozerUtils.map(baseLicenceDto, BaseLicence.class);
        return baseLicenceMapperExt.insertSelective(baseLicence) > 0 ? baseLicence.getId() : 0;
    }

    @Override
    public int update(BaseLicenceDto baseLicenceDto) {
        return baseLicenceMapperExt.updateByPrimaryKeySelective(DozerUtils.map(baseLicenceDto, BaseLicence.class));
    }

    @Override
    public BaseLicenceDto findById(Long aLong) {
        return DozerUtils.map(baseLicenceMapperExt.selectByPrimaryKey(aLong), BaseLicenceDto.class);
    }

    @Override
    public PageInfo<BaseLicenceDto> getList(Pager pager) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        return new PageInfo<>(baseLicenceMapperExt.getList());
    }

    @Override
    public int deleteById(Long id) {
        return baseLicenceMapperExt.deleteById(id);
    }

    @Override
    public List<BaseLicenceDto> selectLicence(BaseLicenceDto dto) {
        return baseLicenceMapperExt.selectLicence(dto);
    }
}
